package org.javaqq.face.main.base;

import java.awt.Color;
import java.awt.Component;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import org.javaqq.face.util.BufferedImageConverter;

public class SearchLabelRenderer extends JLabel implements ListCellRenderer {
	private JList list;
	private Object value;
	private int index;
	private boolean isSelected;
	private boolean cellHasFocus;
	public SearchLabelRenderer(){
		this.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 2));
		setOpaque(true);
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		this.list=list;
		this.value=value;
		this.index=index;
		this.isSelected=isSelected;
		this.cellHasFocus=cellHasFocus;
		setText("");
		setIcon(null);
		/*if (value instanceof MetaContact) {
			MetaContact contact = (MetaContact) value;
			if (contact.getAvatar() != null) {
				try {
					BufferedImage image=BufferedImageConverter.createByteImage(contact.getAvatar());
					image=BufferedImageConverter.getFasterScaledInstance(image, 25, 25, RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
					ImageIcon icon = new ImageIcon(image);
					setIcon(icon);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			setText(contact.getDisplayName());
		}*/
		setBackground(isSelected ? Color.BLUE : Color.WHITE);
	    setForeground(isSelected ? Color.WHITE : Color.BLUE);
		return this;
	}

}
